package com.mzj.saas.mservice.records.mapper;

import com.mzj.saas.commons.DateUtils;
import com.mzj.saas.mservice.records.vo.RecordsListVO;
import org.springframework.jdbc.core.RowMapper;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;

public class RecordsRowMapper implements RowMapper<RecordsListVO> {
    @Override
    public RecordsListVO mapRow(ResultSet rs, int rowNum) throws SQLException {
        RecordsListVO vo = new RecordsListVO();
        vo.setHouseId(rs.getString("houseId"));
        vo.setOrgId(rs.getLong("orgId"));
        vo.setCommunityId(rs.getLong("communityId"));
        vo.setMatchUserId(rs.getString("matchUserId"));
        vo.setApplyId(rs.getLong("applyId"));
        Date submitTime = rs.getDate("submitTime");
        Date confirmTime = rs.getDate("confirmTime");
        vo.setSubmitTime(submitTime == null ? "" : DateUtils.format(submitTime, DateUtils.FORMAT_DATETIME_14));
        vo.setConfirmTime(confirmTime == null ? "" : DateUtils.format(confirmTime, DateUtils.FORMAT_DATETIME_14));

        Long recordsId = 0L;
        if (rs.getObject("recordsId") != null) {
            recordsId = rs.getLong("recordsId");
        } else {
            recordsId = null;
        }
        vo.setRecordsId(recordsId);

        Integer status = 0;
        if (rs.getObject("status") != null) {
            status = rs.getInt("status");
        } else {
            status = null;
        }
        vo.setStatus(status);

        return vo;
    }
}
